# Maintainer: @naveen521kk on Github, Naveen M K <naveen521kk@gmail.com>

_pyname=cookiecutter
_realname=cookiecutter
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.7.3
pkgrel=2
pkgdesc='A command-line utility that creates projects from project templates, e.g. creating a Python package project from a Python package project template. (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/cookiecutter/cookiecutter"
license=('BSD-3-Clause')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-binaryornot"
  "${MINGW_PACKAGE_PREFIX}-python-jinja"
  "${MINGW_PACKAGE_PREFIX}-python-click"
  "${MINGW_PACKAGE_PREFIX}-python-poyo"
  "${MINGW_PACKAGE_PREFIX}-python-jinja2-time"
  "${MINGW_PACKAGE_PREFIX}-python-slugify"
  "${MINGW_PACKAGE_PREFIX}-python-requests"
  "${MINGW_PACKAGE_PREFIX}-python-six"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-setuptools" 
)
source=("${_pyname}-${pkgver}.tar.gz::https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('6b9a4d72882e243be077a7397d0f1f76fe66cf3df91f3115dbb5330e214fa457')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_pyname//_/-}-$pkgver" "python-build-${CARCH}"
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
